"""
@author: 江同学呀
@file: aggregation.py
@date: 2024/7/25 11:36
@desc: 
"""
from typing import Dict, List

from espc.orm.model.base.base import _Base


class _BaseAgg(_Base):
    """
    聚合组件
    """

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self._aggs: Dict[str, Aggregation] = {}
        return

    def aggs(self, **aggs: "Aggregation"):
        self._aggs.update(aggs)
        return self

    def _build_aggs(self, body: Dict) -> Dict:
        """

        :param body:
        :return:
        """
        if self._aggs:
            body["aggs"] = {name: {agg.type: agg._build()} for name, agg in self._aggs.items()}
        return body


class Aggregation(_BaseAgg):
    """
    聚合
    https://www.elastic.co/guide/en/elasticsearch/reference/7.17/search-aggregations.html
    """
    type: str

    def __init__(self):
        super().__init__()
        return



